package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-04-24 21:59
 */
public class EquationsPossible {

    public boolean equationsPossible(String[] equations) {
        UF uf = new UF(26);
        for (String equation : equations) {
            char operator = equation.charAt(1);
            if (operator == '=') {
                uf.union(equation.charAt(0)-'a', equation.charAt(3)-'a');
            }
        }
        for (String equation : equations) {
            char operator = equation.charAt(1);
            if (operator == '!') {
                if (uf.connected(equation.charAt(0)-'a', equation.charAt(3)-'a')) {
                    return false;
                }
            }
        }
        return true;
    }
}
